<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工管理</title>
<!-- 导入jquery核心类库 -->
<%@include file="../include/jqueryeasyui.jsp"%>

<script type="text/javascript">

$(function(){
	main();
});



	function main(){
		 getSessionStaff();
		 initToolBarBtn();
		 initDatagrid();
		 initCeliangBuweiWindow();
		 
	}
	
	function  getSessionStaff(){
		var staff = '<%=session.getAttribute("staff")%>';
		window.staff =  JSON.parse(staff).sLoginName;
	}



	function doAdd(){
	
		$('#celiangbuweiWindow').form('clear');
		$('#celiangbuweiWindow *').trigger('blur');// 离焦
		$('#celiangbuweiWindow').window("open").window('setTitle', '品类管理');
	}
	
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        queryParams.itemName = $('#searchcontent').val();  
        
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
	function doSearch(){
		reloadgrid();
	}
	
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
	        $("input[name='sId']").val(rowData.sId);
			$("input[name='sName']").val(rowData.sName);
			$("input[name='sEmail']").val(rowData.sEmail);
			$("input[name='sPhone']").val(rowData.sPhone);
			$('#sSex').combobox('setValue', rowData.sSex);
			$('#sStatus').combobox('setValue', rowData.sStatus);
	 		$('#dept').combobox('select', rowData.sDeptId);

			// 弹出窗口
			  
			$("#addStandardWindow").window('open').window('setTitle', '修改员工');
        } 
	}
	
	
	var columns = [ [ {
		field : 'itemName',
		title : '部位名称',
		width : 120,	
	},{
		field : 'dimension',
		title : '维度',
		width : 120,
		formatter:formatterDimension
	},{
		field : 'itemID',
		title : '操作',
		width : 160,
		formatter:formatterCaoZuo
	} ] ];
	
	function formatterCaoZuo(value,row,index){
		if(window.staff=='admin'){

			return "<a onclick=doDel("+index+") href=#>删除</a>";
		}else{
			return "";
		}
	}	
	
	function  formatterDimension(value,row,index){
		if(value=='height'){
			return "长度";
		}else if(value=='girth'){
			return '围度';
		}
	}
	
	function doDel(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    if(row){ 

		     $.messager.confirm("操作提示", "确认删除 当前记录？", function (data) {  
		            if (data) {  
		            	$.post("${pageContext.request.contextPath}/page.celiangbuweidel.ashx?itemID="+row.itemID,function(data){
			    			
			    			if(data.status == "1"){
			    				// 成功
			    				$.messager.alert('消息','操作成功 ','info');
			    				reloadgrid();
			    				
			    			
			    			}else{
			    					$.messager.alert('消息','<br>操作失败','info');
			    				
			    			}
			    				
			    		}); 
		            }  
		            else {  
		                 
		            }  
		        }); 


		}
	}
	function doProcess(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    if(row){ 
/* 	    	alert(row.bfId)
 */			location.href="${pageContext.request.contextPath}/page.bfdetails.ashx?bfid="+row.bfid;

		}
	}
	
	function formatterDate(value,row,index){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(value);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
	
	 function formaterbfIsDone(value,row,index){
		if(value==false){
			return "否";
		}else{
			return "是";
		}
	} 
	


	 

	function initToolBarBtn(){
		$('#add').click(doAdd);
		$('#search').click(doSearch);

	}
	function initDatagrid(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/page.celiangbuweiList.ashx",
			idField : 'bfId',
			columns : columns,
			pageList: [10, 20, 50, 100],
			pagination:true,
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>"
			
		});
		
	}
	
	//初始化窗口
	function  initCeliangBuweiWindow(){
	
		$('#celiangbuweiWindow').window({
			
            title: '测量部位管理',
            width: 500,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:true,
            closable:true
            
        });
		
		//提交表单
		$('#save').click(function(){
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/page.saveCeliangbuwei.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#celiangbuweiWindow').window('close');
							// 清除表单数据
							$('#celiangbuweiWindow').form('clear');
							$('#celiangbuweiWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data=="conflict"){
							$.messager.alert('消息','已有此字段，无需再添加 ','info');
						}else{
							$.messager.alert('消息','操作失败 ','info');
						}
							
					});
				}
				
			});	
	}
	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});

	
</script>	
</head>
<body class="easyui-layout" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	
	<div class="easyui-window"  id="celiangbuweiWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div>
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">测量部位管理</td>
					</tr>
					
				
					
					
					
					<tr>
						<td>部位名称</td>
						<td><input id="itemName" name="itemName" type="text" class="easyui-validatebox"  required="true"  /></td>
					</tr>
					 
					
						
				  	<tr>
						<td >测量部位维度</td>
						
						<td colspan="3">
							<select  class="easyui-combobox  "  required="true"  name="dimension" id="dimension" style="width:172px;">
								   <option></option>
								   <option value ="height">长度</option>
								  <option value="girth">围度</option>
							</select> 
							
							
						</td>
					</tr> 
					
					
					
					
				
					</table>
			</form>
		</div>
	</div>


	
		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
 
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;部位名称:&nbsp;&nbsp;&nbsp;&nbsp;<input id="searchcontent" class="easyui-textbox" style="width:80px"/>
			&nbsp;&nbsp;&nbsp;&nbsp;<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
		
		</div>
	</div>

	
</body>
</html>